// Copyright (c) 2002 HTHK
//******************************************************************/
//Modification History
//******************************************************************/
//CR log no 1054: By Oscar Bai  Date:2003/02
//CR log no 1266: By Ploy Li on 2004-04-27
//******************************************************************/

package admin;

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.sql.*;

import admin.system.user.UserBean;
import admin.system.user.UserProcess;

import com.ffpc.servlet.*;
import com.ffpc.sql.*;
import com.ffpc.struts.StrutsMessage;
import com.system.userMultiRole.UserMultiRoleBean;
import com.system.userMultiRole.UserMultiRoleProcess;

public class UserSearchChangePwd extends DBServlet {

	@Override
	protected String perform(HttpServletRequest request, HttpServletResponse response, StrutsMessage message)
		throws ServletException, IOException, SQLException, DataException, Exception {

		String formAction = request.getParameter("formAction");
		UserBean user = UserProcess.createBean();
		user.setUser_id(request.getParameter("user_id"));
		user.setUser_name(request.getParameter("user_name"));
		UserBean[] users = UserProcess.find(this.getConnection(),user);
      
		UserMultiRoleBean userMultiRole = UserMultiRoleProcess.createBean();
		userMultiRole.setUser_id(request.getParameter("user_id"));
		UserMultiRoleBean[] userMultiRoles = UserMultiRoleProcess.find(this.getConnection(),userMultiRole);

    	//System.out.println("\n************* calling UserSearchChangePwd.java *************");
		//System.out.println("UserSearchChangePwd:formAction = " + formAction);
		//System.out.println("UserSearchChangePwd:user = " + user + ", user.getUser_id() = " + user.getUser_id());
		//System.out.println("UserSearchChangePwd:users = " + users + ", length = " + users.length);
		//System.out.println("UserSearchChangePwd:userMultiRoles = " + userMultiRoles + ", length = " + userMultiRoles.length);

		if (users == null || users.length == 0) {
			message.setMessage("No record, please input another criteria.");
			return "system/userSearchChangePwd.jsp";
		}
		else {
			if ("Search".equals(formAction)) {
				request.setAttribute("users",users);
				return "system/userListChangePwd.jsp";
			} else {
				request.setAttribute("user",users[0]);
				request.setAttribute("userMultiRoles",userMultiRoles);
				return "system/userChangePwd.jsp?formAction=Update";
			}
		}
/*
		else if (users.length==1) {
			request.setAttribute("user",users[0]);
			request.setAttribute("userMultiRoles",userMultiRoles);
			return "system/userChangePwd.jsp?formAction=Update";
		}
		else {
			request.setAttribute("users",users);
			return "system/userListChangePwd.jsp";
		}
*/
	}
}

